#include <cstdio>
#include <cstring>

struct Node
{
    Node *left, *right;
    int d;
    Node( ) { left = right = NULL; }
};

int c;

void xian( Node *p, int *a )
{
    if ( !p ) return ;
    a[ c++ ] = p->d;
    xian( p->left, a );
    xian( p->right, a );
}

void zhong( Node *p, int *a )
{
    if ( !p ) return ;
    zhong( p->left, a );
    a[ c++ ] = p->d;
    zhong( p->right, a );
}

int main( )
{
    int n, i, a[ 2 ][ 11 ], b[ 2 ][ 11 ], len1, len2;
    char str[ 11 ];
    Node *head1, *head2, *p;
    while ( scanf("%d", &n) && n )
    {
        scanf("%s", str);
        len1 = strlen( str );
        head1 = new Node;
        head1->d = str[ 0 ];
        for ( i = 1; str[ i ]; i++ )
        {
            p = head1;
            while ( 1 )
                if ( str[ i ] < p->d )
                    if ( p->left )
                        p = p->left;
                    else
                    {
                        p->left = new Node;
                        p->left->d = str[ i ];
                        break;
                    }
                else
                    if ( p->right )
                        p = p->right;
                    else
                    {
                        p->right = new Node;
                        p->right->d = str[ i ];
                        break;
                    }
        }
        c = 0;
        xian( head1, a[ 0 ] );
        c = 0;
        zhong( head1, a[ 1 ] );
        while ( n-- )
        {
            scanf("%s", str);
            len2 = strlen( str );
            if ( len1 != len2 )
            {
                puts("NO");
                continue;
            }
            head2 = new Node;
            head2->d = str[ 0 ];
            for ( i = 1; str[ i ]; i++ )
            {
                p = head2;
                while ( 1 )
                    if ( str[ i ] < p->d )
                        if ( p->left )
                            p = p->left;
                        else
                        {
                            p->left = new Node;
                            p->left->d = str[ i ];
                            break;
                    }
                    else
                        if ( p->right )
                            p = p->right;
                        else
                        {
                            p->right = new Node;
                            p->right->d = str[ i ];
                            break;
                        }
            }
            c = 0;
            xian( head2, b[ 0 ] );
            c = 0;
            zhong( head2, b[ 1 ] );
            for ( i = 0; i < len1; i++ )
                if ( a[ 0 ][ i ] != b[ 0 ][ i ] || a[ 1 ][ i ] != b[ 1 ][ i ] )
                    break;
            if ( i == len1 )
                puts("YES");
            else
                puts("NO");
        }
    }
    return 0;
}
